package com;

import com.pojo.Employee;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
//    查询
    public void findEmployeeTest(){
        SqlSession sqlSession = MyBatisUtils.getSession();
        Employee employee = sqlSession.selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey", (long)1);
        System.out.println(employee);
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
//    添加
    public void insertEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setName("赵六");
        employee.setAge(18);
        employee.setPostion("员工");
        int rows = session.insert("com.mapper.EmployeeMapper.insert", employee);
        session.commit();
        session.close();
    }
    @Test
//    更新
    public void updateEmployeeTest(){
        SqlSession session =MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(5);
        employee.setName("周琪");
        employee.setPostion("员工");
        int rows = session.update("com.mapper.EmployeeMapper.updateByPrimaryKeySelective", employee);
        session.commit();
        session.close();
    }
    @Test
//    删除
   public void deleteEmployeeTest(){
       SqlSession session =MyBatisUtils.getSession();

       int rows = session.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey", 4L);
       session.commit();
       session.close();
    }

}
